<template>
  <div>
    <a-layout id="components-layout-demo-top-side-2">
      <a-layout-header class="header">
        <div class="logo" />
        <a-menu
          theme="dark"
          mode="horizontal"
          :default-selected-keys="['1']"
          :style="{ lineHeight: '64px' }"
        >
          <a-menu-item key="1" @click="go('/homeitem')">nav 1</a-menu-item>
          <a-menu-item key="2" @click="go('/homelist1')">nav 2</a-menu-item>
          <a-menu-item key="3" @click="go('/homelist2')">nav 3</a-menu-item>
          <a-menu-item key="4" @click="go('/homelist3')">nav 4</a-menu-item>
        </a-menu>
      </a-layout-header>
      <a-layout>
        <a-layout-sider width="200" style="background: #fff">
          <a-menu
            mode="inline"
            :default-selected-keys="['1']"
            :style="{ height: '100%', borderRight: 0 }"
          >
            <a-menu-item key="1" @click="go('/homeitem')">表格</a-menu-item>
            <a-menu-item key="2" @click="go('/side1')">option2</a-menu-item>
            <a-menu-item key="3" @click="go('/side2')">option3</a-menu-item>
          </a-menu>
        </a-layout-sider>
        <a-layout style="padding: 0 24px 24px">
          <a-layout-content
            :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
          >
            <router-view />
          </a-layout-content>
        </a-layout>
      </a-layout>
      <!-- <router-view></router-view> -->
    </a-layout>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      show: [],
      list: [],
      onSearchNAME: "",
      onSearchEMAIL: "",
      columns: [
        {
          title: "id名",
          dataIndex: "id",
        },
        {
          title: "会员",
          dataIndex: "role_name",
          scopedSlots: { customRender: "role_name" },
        },
        {
          title: "姓名",
          dataIndex: "name",
          scopedSlots: { customRender: "name" },
        },
        {
          title: "邮箱",
          dataIndex: "email",
          scopedSlots: { customRender: "email" },
        },
        {
          title: "手机号",
          dataIndex: "tell",
          scopedSlots: { customRender: "tell" },
        },
        {
          title: "时间",
          dataIndex: "created_at",
          scopedSlots: { customRender: "created_at" },
        },
        {
          title: "操作",
          dataIndex: "Action",
          scopedSlots: { customRender: "Action" },
        },
      ],
    };
  },
  filters: {
    timefilter: function (value) {
      var date = new Date(value * 1000).toLocaleString();
      return date;
    },
  },
  mounted() {
    axios.get("http://localhost:8080/userlist.json").then((res) => {
      console.log(res.data.data.users);
      this.list = res.data.data.users;
      this.show = res.data.data.users;
    });
  },
  methods: {
    go(str) {
      console.log(str);
      if (str == this.active) {
        return;
      }
      this.$router.push({
        path: str,
      });
    },
    onclick() {
      this.show = [];
      this.list.forEach((ele) => {
        if (ele.name.includes(this.onSearchNAME)) {
          this.show.push(ele);
        }
      });
    },
    onclick1() {
      this.show = [];
      this.list.forEach((ele) => {
        if (ele.email.includes(this.onSearchEMAIL)) {
          this.show.push(ele);
        }
      });
    },
    RowDELL(props) {
      console.log(props);
      var a = this.show.findIndex((e) => {
        return (e.id = props.id);
      });
      if (a != -1) {
        this.show.splice(a, 1);
      }
    },
    // 重置
    original() {
      this.show = this.list;
    },
    // 升序
    UP() {
      this.show.sort((a, b) => {
        return a.created_at - b.created_at;
      });
    },
    DOWN() {
      this.show.sort((a, b) => {
        return b.created_at - a.created_at;
      });
    },
  },
};
</script>

<style scoped>
#components-layout-demo-top-side-2 .logo {
  width: 120px;
  height: 31px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px 28px 16px 0;
  float: left;
}
</style>
